package com.useeinfo.oa.modules.wuHanCommon.base.biz;

import com.useeinfo.framework.extend.biz.CrudBiz;
import com.useeinfo.framework.sugar.data.QueryParam;
import com.useeinfo.framework.sugar.tools.DateTimeUtils;
import com.useeinfo.framework.sugar.tools.StringConverters;
import com.useeinfo.oa.modules.wuHanCommon.base.dao.WarningCreateAcceptDao;
import com.useeinfo.oa.modules.wuHanCommon.base.entity.WarningCreateAccept;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class WarningCreateAcceptBiz extends CrudBiz<WarningCreateAcceptDao, WarningCreateAccept> {

    public Boolean isExist(String projId, String token) {
        if (StringUtils.isBlank(projId)) {
            return false;
        }
        QueryParam queryParam = new QueryParam();
        queryParam.getSqlMap().put("projId", projId);
        queryParam.getSqlMap().put("token", token);
        queryParam.getSqlMap().put("errCode", "0");
        List<WarningCreateAccept> warningCreateAcceptList = this.findList(queryParam);
        return CollectionUtils.isNotEmpty(warningCreateAcceptList);
    }

    //检查1小时内有没有报警消息，没有则推送邮件
    public Boolean isWarmingMessage(){

        String beforeHours=DateTimeUtils.formatDateToStringWithTime(DateTimeUtils.addHourOfDay(new Date(),-1));
        String hql="select obj from WarningCreateAccept obj where obj.createDate >='"+beforeHours+"'";
        List<WarningCreateAccept>warningCreateAccepts=dao.hqlExcute(hql);
        return CollectionUtils.isEmpty(warningCreateAccepts);
    }

    public String getDate() {
        List<Object> objects = dao.getDate();
        return objects.get(0).toString();
    }
}
